package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Car;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author wulei
 * @Date 2018/8/23
 */

public class CarManagementAdapter extends RecyclerAdapter<Car, CarManagementAdapter.CarViewHolder> {

    public CarManagementAdapter(Context context, List<Car> dataList) {
        super(context, dataList);
    }

    @Override
    public CarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_car, null);
        return new CarViewHolder(view);
    }

    @Override
    public void onBindViewHolder(CarViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class CarViewHolder extends RecyclerAdapter.BaseViewHolder {
        @BindView(R.id.car_num)
        HXTextView carNum;
        @BindView(R.id.car_time)
        HXTextView carTime;
        @BindView(R.id.car_type)
        HXTextView carType;

        public CarViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            Car car = dataList.get(position);
            carNum.setText(car.getPlateNo());
            carTime.setText(car.getCreateTime());
            if(car.getDirection() == 0){
                carType.setText(R.string.enter);
                carType.setEnabled(true);
            }else if(car.getDirection() == 1){
                carType.setText(R.string.exit);
                carType.setEnabled(false);
            }
        }
    }
}
